package com.hrs.core.controller;

import com.hrs.common.anno.NoValidPrivilege;
import com.hrs.common.constant.SwaggerConst;
import com.hrs.common.result.Result;
import com.hrs.core.service.PositionService;
import com.hrs.enity.ro.PositionAddRo;
import com.hrs.enity.ro.PositionUpdateRo;
import com.hrs.enity.vo.PositionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 摆渡人
 * @description
 * @date 2023/1/12 23:52
 */
@Api(tags = {SwaggerConst.Admin.MANAGER_POSITION})
@RestController
public class PositionController {

    @Autowired
    private PositionService positionService;

    @ApiOperation(value = "查询岗位树形列表")
    @GetMapping("/position/tree")
    @NoValidPrivilege
    public Result<List<PositionVo>> listPosition() {
        return positionService.listPosition();
    }

    @ApiOperation(value = "查询岗位列表")
    @GetMapping("/position/listAll")
    @NoValidPrivilege
    public Result<List<PositionVo>> listAll() {
        return positionService.listAll();
    }

    @ApiOperation(value = "根据id获取岗位信息")
    @GetMapping("/position/query/{pid}")
    @NoValidPrivilege
    public Result<PositionVo> getPosition(@PathVariable Integer pid) {
        return positionService.getPositionById(pid);
    }

    @ApiOperation(value = "添加岗位")
    @PostMapping("/position/add")
    @NoValidPrivilege
    public Result<String> addPosition(@Validated @RequestBody PositionAddRo positionAddRo) {
        return positionService.addPosition(positionAddRo);
    }

    @ApiOperation(value = "更新岗位信息")
    @PostMapping("/position/update")
    @NoValidPrivilege
    private Result<String> updatePosition(@Validated @RequestBody PositionUpdateRo positionUpdateRo) {
        return positionService.updatePosition(positionUpdateRo);
    }

    @ApiOperation(value = "删除岗位")
    @PostMapping("/position/delete/{pId}")
    @NoValidPrivilege
    public Result<String> delPosition(@PathVariable Integer pId) {
        return positionService.delPosition(pId);
    }

}
